//
//  TrackDeviceInfoModel.m
//  YuanXinTrack
//
//  Created by GJS on 2018/5/10.
//  Copyright © 2018年 GJS. All rights reserved.
//

#import "TrackDeviceInfoModel.h"
#import "DeviceInfoManager.h"

#define kFormatStr @"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"

@implementation TrackDeviceInfoModel

- (instancetype)init
{
    self = [super init];
    if (self) {
        _uuid = [[[NSUUID UUID] UUIDString] lowercaseString];
        _deviceName = [[UIDevice currentDevice] name];
        _systemName = [[UIDevice currentDevice] systemName];
        _initialFirmware = [[DeviceInfoManager sharedManager].getInitialFirmware copy];
        _latestFirmware = [[DeviceInfoManager sharedManager].getLatestFirmware copy];
        _systemVersion = [[UIDevice currentDevice] systemVersion];
        _MacAddress = [[DeviceInfoManager sharedManager].getMacAddress copy];
        _IDFA = [[DeviceInfoManager sharedManager].getIDFA copy];
        _uniqueID = [[DeviceInfoManager sharedManager].getUniqueID copy];
        _deviceModel = [[DeviceInfoManager sharedManager].getDeviceModel copy] ?: @"Unknown";
        _deviceModelName = [[DeviceInfoManager sharedManager].getDeviceName copy];
        _systemUptime = [[DeviceInfoManager sharedManager].getSystemUptime copy];
        _CPUCount = [DeviceInfoManager sharedManager].getCPUCount;
        _deviceLanguage = [NSLocale preferredLanguages].firstObject;;
        _timeZone = [NSTimeZone systemTimeZone];
    }
    return self;
}

// 设置日期格式
// [formatter setDateFormat:@"yyyy-mm-dd HH:mm:ss"];
// [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"];
- (NSString *)strFromDate:(NSDate *)date formatStr:(NSString *)formatStr {

    // 实例化NSDateFormatter
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    // 设置日期格式
    [formatter setDateFormat:formatStr ?: kFormatStr];
    formatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
    formatter.timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
    // 转成字符串
    NSString *dateString = [formatter stringFromDate:date];

    return dateString;
}

// 要转换的日期字符串
// NSString *dateString = @"2011-05-03 23:11:40";
// NSString *dateString = @"2018-05-11T07:20:21.487Z";
// NSTimeZone *timezone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];
- (NSDate *)dateFromStr:(NSString *)dateString formatStr:(NSString *)formatStr {

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    // 设置日期格式
    [formatter setDateFormat:formatStr ?: kFormatStr];
    formatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
    formatter.timeZone = [NSTimeZone timeZoneWithName:@"UTC"];

    NSDate *someDay = [formatter dateFromString:dateString];

    return someDay;
}

@end
